// pages/mine/picker/index.js
const App = getApp()
import Util from '../../../utils/util'

Page({
  data: {
    init: false,
    loading: false,
    CustomBar: App.Global.CustomBar,

    items: []
  },
  onLoad() {
    wx.sub('ReloadPickerInfo', this, () => {
      this.execLoad()
    })
    this.execLoad()
  },
  onUnload() {
    wx.cancel('ReloadPickerInfo', this)

  },


  execLoad() {
    this.setData({
      loading: true
    })
    App.doPost({
      uri: '/app/user/picker/list',
      body: {

      },
      fnSucc: resp => {
        this.setData({
          init: true,
          loading: false,
          items: resp.data.items
        })
      },
    })
  },
  // 跳转页面
  toPage(e) {
    wx.navigateTo({
      url: e.currentTarget.dataset.uri
    })
  },

  doDelete(e) {
    let clk = e.currentTarget.dataset.clk
    Util.Dialog.confirm(`是否删除[${clk.dlc.name}]？`, () => {
      this.execDelete(clk.id)
    })
  },
  execDelete(id) {
    this.setData({
      loading: true
    })
    App.doPost({
      uri: '/app/user/picker/delete',
      body: {
        ids: [id]
      },
      fnSucc: () => {
        this.execLoad()
      }
    })
  },

})